package com.wetool.wechat.config;

import com.wetool.wechat.feign.MinaFeignClient;
import com.wetool.wechat.feign.WechatOfficialFeignClient;
import com.wetool.wechat.feign.WechatOpenPlatformFeignClient;
import feign.Feign;
import feign.Logger;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignConfig {

    @Value("${wechat.official-server.url}")
    private String wechatUrl;

    @Bean()
    public WechatOpenPlatformFeignClient wechatLoginClient() {
        return Feign.builder()
                .decoder(new JacksonDecoder())
                .encoder(new JacksonEncoder())
                .logger(new Slf4jLogger()).logLevel(Logger.Level.FULL)
                .target(WechatOpenPlatformFeignClient.class, wechatUrl);
    }

    @Bean()
    public WechatOfficialFeignClient wechatOfficialFeignClient() {
        return Feign.builder()
                .decoder(new JacksonDecoder())
                .encoder(new JacksonEncoder())
                .logger(new Slf4jLogger()).logLevel(Logger.Level.FULL)
                .target(WechatOfficialFeignClient.class, wechatUrl);
    }
    
    @Bean()
    public MinaFeignClient minaFeignClient() {
        return Feign.builder()
                .decoder(new JacksonDecoder())
                .encoder(new JacksonEncoder())
                .logger(new Slf4jLogger()).logLevel(Logger.Level.FULL)
                .target(MinaFeignClient.class, wechatUrl);
    }
}
